/**
 * Created by Kpeng on 2017/7/10.
 * Depending on the jquery-1.11.3.min.js.
 * Depending on the style.css.
 * To cite this document, always state the source as shown above.
 */

$(function () {
  wzERP.Countries.init();
});

wzERP.Countries.init = function () {
  wzERP.Countries.dataHandle(); //新增编辑国家地区
  wzERP.Countries.delHandle(); //删除国家地区
};

//新增编辑操作
wzERP.Countries.dataHandle = function () {
  var opt = {
    addBtn: '#addBtn',
    wrapper: "#main",
    container: ".table-edit tbody",
    submitForm: "#submitForm",
    saveBtn: ".saveBtn",
    editBtn: ".editBtn",
    cancelBtn: ".cancelBtn",
    saveFn: function () {
      var curRow = this.event.parents('tr'),
          //错误回调
          errFn = function () {
            curRow.addClass('editing');
            curRow.find('[data-name="selectCurrentcyName"]').css('display',
                'block');
            curRow.find('[data-name="inputCurrentcyName"]').css('display',
                'none');
          },
          //成功回调
          successFn = function () {
            wzERP.Common.delayReload(wzERP.delayTime);
          };

      wzERP.Common.saveHandle("#submitForm", "#countyAddUrl", this.event, '',
          successFn, errFn);

    }
  }
  wzERP.Common.editTable(opt);
};

//删除操作
wzERP.Countries.delHandle = function () {
  /*var opt = {
   ele: '.delBtn',
   modalBox: '#modal',
   modalTitleStr: '',
   onApprove: function () {
   wzERP.Common.deleteData('#delCountyUrl', $(this).find('.setId'));
   },
   snippets: $('#deleCountyPageUrl').val()
   };
   wzERP.Common.handleData(opt);*/

  $('#main').on('click', '.delBtn', function () {
    var $self = $(this);
    layer.alert('确定删除该国家/地区吗？', {
          title: '提示信息',
          btn: ['取消', '确认'],
          btn1: function (index) {
            layer.close(index)
          },
          btn2: function () {
            wzERP.Common.deleteData('#delCountyUrl', $self)
          }
        }
    );
  })
};